//
//  TWChoicenessItemCell.swift
//  EyepetizerImitative
//
//  Created by 田伟 on 2017/3/10.
//  Copyright © 2017年 个人. All rights reserved.
//  显示视频的cell

import UIKit
import SDWebImage

class TWChoicenessItemCell: UITableViewCell {
    
    // MARK:- 控件
    @IBOutlet weak var bgImageView: UIImageView!                    // 显示背景大图
    @IBOutlet weak var titleLabel: UILabel!                         // 显示标题
    @IBOutlet weak var timeLable: UILabel!                          // 显示分类以及时间
    
    
    // MARK:- 自定义属性
    var itemModel : TWItemModel? {
        didSet {
            guard let itemModel = itemModel else {
                return
            }
            // 设置控件
            bgImageView.sd_setImage(with: URL(string: (itemModel.cover?.detail)!))
            bgImageView.contentMode = .scaleAspectFill
            titleLabel.text = itemModel.title
            timeLable.text = "#\(itemModel.category!)" + " / " + "\(itemModel.duration_tw!)"
        }
    }
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
//        let height = UIScreen.main.bounds.height
//        let width = UIScreen.main.bounds.width
//
//        bgImageView.frame = CGRect(x: 0, y: -(height / 1.7 - 250) / 2, width: width, height: height / 1.7)
    }
}

extension TWChoicenessItemCell {
    /// 计算偏移量
//    func cellOffset(){
//        // 拿到cell在窗口上的位置
//        let centerToWindow = convert(self.bounds, to: self.window)
//        // 拿到cell在窗口上的Y轴的中心点坐标
//        let centerY = centerToWindow.midY
//        // 拿到tableView的中心点
//        let windowCenter = self.superview?.center
//        let cellOffsetY = centerY - windowCenter!.y
//        let offsetDig = cellOffsetY / superview!.frame.size.height * 2
//        let height = UIScreen.main.bounds.height
//        let offset = -offsetDig * (height/1.7 - 250) / 2
//        /*
//         centerToWindow————————(0.0, 249.666666666667, 414.0, 240.119995117187)
//         centerY————————————————369.72666422526
//         windowCenter?.y————————Optional(243.0)
//         126.72666422526
//         0.521508906276792
//         -47.702726427083
//         -47.702726427083
//         */
//        
//        let taransY = CGAffineTransform(translationX: 0, y: offset)
//        bgImageView.transform = taransY
//    }
}
